<template>
    <div class="website-information">
        <el-card class="!border-none" shadow="never">
            <div>
                <el-button type="primary"  @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    添加接入
                </el-button>
            </div>
            <el-table ref="tableRef" class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" row-key="id">
                <el-table-column label="id" prop="id" min-width="100" />
                <el-table-column label="添加时间" prop="create_time" min-width="150" show-overflow-tooltip />
                <el-table-column label="服务器URL" prop="url" min-width="150" show-overflow-tooltip />
                <el-table-column label="备注" prop="remark" min-width="150" show-overflow-tooltip />
                <el-table-column label="操作" width="200" fixed="right">
                    <template #default="{ row }">
                        <el-button type="primary" link @click="handleEdit(row)">
                            编辑
                        </el-button>
                        <el-button type="danger" link @click="handleDelete(row.id)">
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex mt-4 justify-end">
                <paginat v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup>
import {  hostList,delHost } from '@/api/application/gzh/index'
import { usePaging } from '@/hooks/usenew'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const route = useRoute()
const formData = reactive({
    wechat_id:route.query.id
})
const { pager, getLists } = usePaging({
    fetchFun: hostList,
    params: formData
})

const handleAdd = async (id?: number) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}
const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}
const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await delHost({ id })
    getLists()
}
getLists()
</script>